package com.qiantu.phone.ui.dialog;

import android.content.Context;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.LinearLayoutCompat;

import com.qiantu.api.entity.DeviceCustomKeyBean;
import com.qiantu.phone.R;
import com.qiantu.phone.widget.btnview.OnBtnClickListener;
import com.qiantu.phone.widget.btnview.OnBtnLongClickListener;
import com.qiantu.phone.widget.btnview.TotalBtnView;
import com.lxj.xpopup.core.BottomPopupView;

import java.util.List;

public class BottomKeyStudyDialog extends BottomPopupView {
    private int mKeyCount;
    private ImageView step1Check;
    private LinearLayoutCompat step1Text;
    private ImageView step2Check;
    private LinearLayout step2Text;
    private ImageView step3Check;
    private LinearLayout step3Text;
    private TotalBtnView totalBtnView;

    public BottomKeyStudyDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_key_study;
    }

    // 执行初始化操作，比如：findView，设置点击，或者任何你弹窗内的业务逻辑
    @Override
    protected void onCreate() {
        super.onCreate();
        initView();
    }

    private void initView() {
        step1Check = (ImageView) findViewById(R.id.step_1_check);
        step1Text = (LinearLayoutCompat) findViewById(R.id.step_1_text);
        step2Check = (ImageView) findViewById(R.id.step_2_check);
        step2Text = (LinearLayout) findViewById(R.id.step_2_text);
        step3Check = (ImageView) findViewById(R.id.step_3_check);
        step3Text = (LinearLayout) findViewById(R.id.step_3_text);
        totalBtnView = findViewById(R.id.btns);
        totalBtnView.setKeyCount(mKeyCount);
        totalBtnView.setOnBtnClickListener(mClickListener);
        totalBtnView.setOnBtnLongClickListener(mLongClickListener);
    }

    // 设置最大宽度，看需要而定
    @Override
    protected int getMaxWidth() {
        return super.getMaxWidth();
    }

    // 设置最大高度，看需要而定
    @Override
    protected int getMaxHeight() {
        return super.getMaxHeight();
    }

    /**
     * 弹窗的宽度，用来动态设定当前弹窗的宽度，受getMaxWidth()限制
     *
     * @return
     */
    protected int getPopupWidth() {
        return 0;
    }

    /**
     * 弹窗的高度，用来动态设定当前弹窗的高度，受getMaxHeight()限制
     *
     * @return
     */
    protected int getPopupHeight() {
        return 0;
    }

    OnBtnLongClickListener mLongClickListener;
    public void setOnBtnLongClickListener(OnBtnLongClickListener listener){
        mLongClickListener = listener;
    }

    OnBtnClickListener mClickListener;
    public void setOnBtnClickListener(OnBtnClickListener listener){
        mClickListener = listener;
    }

    public void setKeyCount(int count){
        mKeyCount = count;
        if (totalBtnView != null){
            totalBtnView.setKeyCount(count);
        }
    }

    public void initCustomKeyInfo(List<DeviceCustomKeyBean> customKeyList) {
        if (totalBtnView != null && customKeyList != null && !customKeyList.isEmpty()){
            totalBtnView.initCustomKeyInfo(customKeyList);
        }
    }

    public void setCustomKeyName(String keyID, String name){
        if (totalBtnView != null){
            totalBtnView.setCustomKeyName(keyID, name);
        }
    }
}
